package cn.sumpu.app.guoguojie.dao.impl;

import java.util.List;
import java.util.Map;

import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.sumpu.app.guoguojie.dao.MemberOutAccountDao;
import cn.sumpu.app.guoguojie.domain.MemberOutAccount;
import cn.sumpu.app.guoguojie.exception.AppBusinessException;

public class MemberOutAccountDaoImpl extends SqlSessionDaoSupport implements MemberOutAccountDao {
	private static Logger logger = LoggerFactory.getLogger(MemberOutAccountDaoImpl.class);
	@Override
	public void insertMemberOutAccount(MemberOutAccount outAccount)
			throws AppBusinessException {
		try {
			getSqlSession()
					.insert("cn.sumpu.app.guoguojie.persistence.MemberOutAccountMapper.insertMemberOutAccount",
							outAccount);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("Insert database failure.", e);
			}
			throw new AppBusinessException("Write database failure.", e);
		}

	}

	@Override
	public MemberOutAccount getMemberOutAccount(Map<String, Object> map)
			throws AppBusinessException {
		try {
			return (MemberOutAccount) getSqlSession()
					.selectOne(
							"cn.sumpu.app.guoguojie.persistence.MemberOutAccountMapper.getMemberOutAccount",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getMemberOutAccount database failure.", e);
			}
			throw new AppBusinessException("getMemberOutAccount database failure.",
					e);
		}

	}

	@Override
	public void UpdateMemberOutAccount(MemberOutAccount outAccount)
			throws AppBusinessException {
		try {
			getSqlSession().update("cn.sumpu.app.guoguojie.persistence.MemberOutAccountMapper.updateMemberOutAccount",outAccount);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("UpdateMemberOutAccount failure.", e);
			}
			throw new AppBusinessException("UpdateMemberOutAccount failure.", e);
		}
		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<MemberOutAccount> getOutAccountList(Map<String, Object> map)
			throws AppBusinessException {
		try {
			return (List<MemberOutAccount>) getSqlSession()
					.selectList(
							"cn.sumpu.app.guoguojie.persistence.MemberOutAccountMapper.getMemberOutAccount",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getOutAccountList database failure.", e);
			}
			throw new AppBusinessException("getOutAccountList database failure.",
					e);
		}
	}

}
